import {objDeepCopy} from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getAllProvince(this);
			this.getSelfLiftCities(this);
			this.changeStore(this);		//获取发货门店
			this.getoriginChannel(this);	//获取来源渠道
			this.Model.filterOption2 = _.cloneDeep(this.Model.defaultFilterOption2);
		},
		//新增(现货/定制/补购)订单接口
		getNewOrder(that,params,pathName) {	
			var params = this.Model.params;
			this.$ajax({
			  method: 'post',
			  url:this.apiTest+'/sale/saleOrder',
			  //url:'/api/sale/saleOrder',
			  data:params
			}).then((res)=>{
				var data = res.data;
					if(data.status == 200){
						this.Model.payPos = false;
						this.tips(this,'success','新增成功');
						var result = data.result;
						console.log(result);
						this.Model.linktoResult = result;
						if(pathName != 0){
							var linktoResult = result;
							that.Model.payPos = false;
							that.$router.push({
								path:'customizeOrderDetail',
								query:{
									saleNumber:linktoResult.orderNo,
									id:linktoResult.id,
									to:pathName
								}
							});
						}else{
							//返回列表
							setTimeout(function(){
								that.$router.push({
									path:'customizeOrder',
									query:{
										isRefresh:true
									}
								});
								
							},1000)
						}
					}else{
						this.tips(this,'warning',data.msg)
					}
			    
			});
		},
		//查询男士身份证
		checkPassword() {
			var IDCard = this.Model.params.idCard;
			if(IDCard){
				this.firstBuy(this,IDCard);
				this.getUserMsg(this,IDCard,'IDCard');
			}else{
				this.tips(this,'warning','请填写身份证号')
				return
			}
			
		},
		//是否首次购买接口
		firstBuy(that,IDCard) {
			IDCard = IDCard || '';
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/sale/saleOrder/buy/'+IDCard,
			}).then((res)=>{
				var data = res.data;
				
				if(data.status == 200){
					var result = data.result;
					that.Model.womanRingStatus = true ;
					that.Model.womanRingPay = !result;
				}else{
					that.tips(that,'warning',data.msg)
				}			
			});
		},
		//通过身份证获取用户信息和收货地址
		getUserMsg(that,number,type) {
			if(number == ''){
				return;
			}
			var url;
			if(type == 'IDCard'){
				url = this.apiTest+'/crm/customerInfo/sale/findByIDCard?IDCard='+number;
			}else if(type == 'phoneNo'){
				url = this.apiTest+'/crm/customerInfo/sale/findByPhone?phoneNum='+number;
			}
			this.$ajax({
				method: 'get',
				url:url,
			}).then((res)=>{
				 var data = res.data;
				 if(data.status == 200){
					var arr = [];
					var result = data.result;
					if(result){
						that.Model.params.isNewUser = false;
						that.Model.basicMsgDisabled = true;			
						that.Model.params.womanName = result.femaleName;//女士姓名
						that.Model.params.ladiesPhone = result.femalePhone;//女士手机号
						that.Model.params.manName = result.maleName;//男士姓名
						that.Model.params.mobile = result.phone;//男士手机号
						that.Model.params.sexuality = String(result.sexOrientation);//恋爱属性
						that.Model.params.exclusiveCode = result.exclusiveCode;//专属编码
						//
						var list = result.receiverInfoList;
						for(var i  = 0; i < list.length; i++){
							that.Model.haveAdress = true;
							var locationName = list[i].geographyProvince.provinceName+list[i].geographyCity.cityName+list[i].geographyArea.areaName;//省市县组合的字段
							var obj = {
								id:list[i].id,
								recipientName:list[i].name,
								recipientPhone:list[i].phone,
								informPhone:list[i].informPhone,
								addressType:String(list[i].addressType),
								locationArea:[list[i].provinceCode,list[i].cityCode,list[i].areaCode],
								locationName:locationName,
								detailedAddress:list[i].address,
								alternativeAddress:'',
								defaultAddress:list[i].defaultAddress,
							}
							arr.push(obj);
							//是否默认
							if(list[i].defaultAddress == 1){							
								that.Model.radioAddress = list[i].id;
								//将默认地址填入 下方地址信息
								this.getAllCity(this,list[i].provinceCode);
								this.getAllCounty(this,list[i].provinceCode,list[i].cityCode)
								that.Model.selectedOptions3 = [list[i].provinceCode,list[i].cityCode,list[i].areaCode];
								//需要新增的地址信息
								that.Model.checkedAddress = {
									recipientName:list[i].name,
									recipientPhone:list[i].phone,
									informPhone:list[i].informPhone,
									addressType:String(list[i].addressType),
									locationArea:[list[i].provinceCode,list[i].cityCode,list[i].areaCode],
									locationName:locationName,
									detailedAddress:list[i].address,
									alternativeAddress:''
								}
							}
						}
						that.Model.params.saleReceivingList = objDeepCopy(arr);//收货信息
					}else{
						that.Model.params.isNewUser = true;
						that.Model.haveAdress = false;
						that.Model.basicMsgDisabled = false;
						that.Model.params.womanName = '';
						that.Model.params.ladiesPhone = '';
						that.Model.params.manName = '';
						that.Model.params.sexuality = '';
						that.Model.params.exclusiveCode = '';
					}
					that.Model.params.saleReceivingList = objDeepCopy(arr);//收货信息
				}else{
				 								
				}
					
			});
		},
		//失去焦点 电话号码查询 
		queryPhone() {
			var phoneNo = this.Model.mobile;
			var that = this;
			this.getUserMsg(this,phoneNo,'phoneNo');
		},
		toggleDialog(status,refresh) {
			this.Model.changeGoodsDialogFlag = status;
			this.getSalesClassify();
			//判断是新增还是编辑
			if(refresh){
				
			}
		},
		backSpotOrder() {
			this.$router.push({
				path: 'customizeOrder'
			})
		},
		//切换省市区
		handleItemChange(val) {
			console.log(val)
			if(val.length == 1){
				var provinceCode = val[0];
				this.getAllCity(this,provinceCode);
			}else if(val.length == 2){
				var provinceCode = val[0];
				var cityCode = val[1];
				this.getAllCounty(this,provinceCode,cityCode)
			}
		},
		//获取省
		getAllProvince(that) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/crm/geographyProvince/queryProvinceList?language=1&countryCode=CN',
				//url:'/api/crm/geographyProvince/queryProvinceList?language=1&countryCode=CN',
			}).then((res)=>{
				 var data = res.data;
				 if(data.status == 200){
					 that.options = [];
						var result = data.result;
						for(var i  = 0; i < result.length; i++){
							var obj = {
									code: result[i].provinceCode,
									label: result[i].provinceName,
									children:[]
							}
							that.Model.options.push(obj);
						}
				 }else{
						
				 }
					
			});
		},
		//获取市
		getAllCity(that,provinceCode) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/crm/geographyCity/queryCityList?language=1&countryCode=CN&provinceCode='+provinceCode,
				//url:'/api/crm/geographyCity/queryCityList?language=1&countryCode=CN&provinceCode='+provinceCode,
			}).then((res)=>{
				 var data = res.data;
				 if(data.status == 200){
						var result = data.result;
						var options = that.Model.options;
						var cities = [];
						//遍历数据
						for(var i  = 0; i < result.length; i++){
							var obj = {
									code: result[i].cityCode,
									label: result[i].cityName,
									children:[]
							}
							cities.push(obj);
						}
						//查找 相对应的省
						for(var i  = 0; i < options.length; i++){
							if(options[i].code == provinceCode){
								options[i].children  = objDeepCopy(cities);
							}
						}
				 }else{
						
				 }
					
			});
		},
		//获取区（县）
		getAllCounty(that,provinceCode,cityCode) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/crm/geographyArea/queryAreaList?language=1&countryCode=CN&provinceCode='+provinceCode+'&cityCode='+cityCode,
				//url:'/api/crm/geographyArea/queryAreaList?language=1&countryCode=CN&provinceCode='+provinceCode+'&cityCode='+cityCode,
			}).then((res)=>{
				 var data = res.data;
				 if(data.status == 200){
						var result = data.result;
						var areas = [];
						var options = that.Model.options;
						//遍历数据
						for(var i  = 0; i < result.length; i++){
							var obj = {
									code: result[i].areaCode,
									label: result[i].areaName
							}
							areas.push(obj);
						}
						//查找 相对应的区（县）
						for(var i  = 0; i < options.length; i++){
							if(options[i].code == provinceCode){
								var cities = options[i].children;
								for(var j  = 0; j < cities.length; j++){
									if(cities[j].code == cityCode){
										cities[j].children  = objDeepCopy(areas);
									}
								}
							}
						}
				 }else{
						
				 }
					
			});
		},
		//获取销售分类
		getSalesClassify() {
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/sale/saleGoodsAttribute/getGoodsAttributelist',
				//url:'/api/sale/saleGoodsAttribute/getGoodsAttributelist',
				data:{
					attributeCode:"M05"
				}
			}).then((res1)=>{
				const data1 = res1.data;
				if (data1.status == 200) {
					this.$ajax({
						method: 'post',
						url:this.apiTest+'/sale/saleGoodsAttribute/getGoodsAttributelist',
						//url:'/api/sale/saleGoodsAttribute/getGoodsAttributelist',
						data:{
							attributeCode:"M04"
						}
					}).then((res2)=>{
						const data2 = res2.data;
						if (data2.status == 200) {
							this.setFilterOption2(data1.result, data2.result);
						}
					})
				}
			})		
		},
		setFilterOption2(arr1, arr2) {
			this.Model.filterOption2 = _.cloneDeep(this.Model.defaultFilterOption2);
			// this.Model.filterOption2 = this.Model.defaultFilterOption2;
			this.Model.filterOption2.items[0].data = arr1.map(item => {
				return {
					label: item.attributeValueName,
					// value: item.id
					value: item.attributeValueCode
				}
			});
			this.Model.filterOption2.items[1].data = arr2.map(item => {
				return {
					label: item.attributeValueName,
					// value: item.id
					value: item.attributeValueCode
				}
			});
			//this.toggleDialog(true);
		},
		//输入系列修改款式名称
		changeStyleName(that,prams,option){
			prams = prams || {}
			this.$ajax({
		        method: 'post',
		        url:this.apiTest+'/sale/saleGoodsStyle/findStyleASeriesOf/'+prams,
				//url:'/api/sale/saleGoodsStyle/findStyleASeriesOf/'+prams,
		        data:{
		        	
		        }
		  	}).then((res)=>{
		        var data = res.data;
		        if(data.status == 200){
                    this.Model.filterOption2.items[2].value='';
                    this.Model.filterOption2.items[2].data = [];               
					this.Model.filterOption2.items[2].data = data.result.map(item => {
						return {
							label: item.modelName,
							value: item.id
						}
					})
					
		        }else{
					this.tips(this,'warning',data.msg)
		        }
		
		    });
		},
		//获取第二步数据
		getParameters(that,prams,option) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/sale/saleGoodsStyle/condition/'+prams,
				//url:'/api/sale/saleGoodsStyle/condition/'+prams,
				data:{
					
				}
			}).then((res)=>{
				var data = res.data;	
				if(data.status == 200){				
					var result = data.result;
                    console.log(result);
                    /*if(result.attrMap.M15){
                        this.Model.filterOption3.items[3].data = result.attrMap.M15.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //手寸
                    if(result.handInchList){
                        this.Model.filterOption3.items[4].data = result.handInchList.map(item => {
                            return {
                                label: item,
                                value: item
                            }
                        });
                    }
                    //净度
                    if(result.attrMap.M10){
                        this.Model.filterOption3.items[5].data = result.attrMap.M10.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //对称
                    if(result.attrMap.M13){
                        this.Model.filterOption3.items[6].data = result.attrMap.M13.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //抛光
                    if(result.attrMap.M12){
                        this.Model.filterOption3.items[7].data = result.attrMap.M12.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //链长
                    if(result.attrMap.M17){
                        this.Model.filterOption3.items[8].data = result.attrMap.M17.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //颜色
                    if(result.attrMap.M09){
                        this.Model.filterOption3.items[9].data = result.attrMap.M09.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    //切工
                    if(result.attrMap.M11){
                        this.Model.filterOption3.items[10].data = result.attrMap.M11.map(item => {
                            return {
                                label: item.attributeValueName,
                                value: item.attributeValueCode
                            }
                        });
                    }
                    
                    if(result.range){
                        var weightMin = parseInt(result.range.fromTheRabbet*100);//钻重最小值
                        var weightMax = parseInt(result.range.theRabbet*100);//钻重最小值
                        this.Model.weightMin=weightMin;
                        this.Model.weightMax=weightMax;
                        var weightArr =[];
                        for (var i = weightMin; i < weightMax+1; i++) {				
                            weightArr.push(i);
                        }
                        //钻重
                        this.Model.sliderSelect = {
                            weight:{
                                value:'',
                                option:weightArr.map(item => {
                                    return {
                                        label: item,
                                        value: item
                                    }
                                }),
                                sliderVal:[weightMin,weightMax],
                                
                            }
                        }
                    }*/    
					//材质
					this.Model.filterOption3.items[3].data = result.attrMap.M15.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//手寸
					this.Model.filterOption3.items[4].data = result.handInchList.map(item => {
						return {
							label: item,
							value: item
						}
					});
					//净度
					this.Model.filterOption3.items[5].data = result.attrMap.M10.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//对称
					this.Model.filterOption3.items[6].data = result.attrMap.M13.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//抛光
					this.Model.filterOption3.items[7].data = result.attrMap.M12.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//链长
					this.Model.filterOption3.items[8].data = result.attrMap.M17.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//颜色
					this.Model.filterOption3.items[9].data = result.attrMap.M09.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					//切工
					this.Model.filterOption3.items[10].data = result.attrMap.M11.map(item => {
						return {
							label: item.attributeValueName,
							value: item.attributeValueCode
						}
					});
					var weightMin = parseInt(result.range.fromTheRabbet*100);//钻重最小值
					var weightMax = parseInt(result.range.theRabbet*100);//钻重最小值
					this.Model.weightMin=weightMin;
					this.Model.weightMax=weightMax;
					var weightArr =[];
					for (var i = weightMin; i < weightMax+1; i++) {				
						weightArr.push(i);
                    }
					//钻重
					this.Model.sliderSelect = {
						weight:{
							value:'',
							option:weightArr.map(item => {
								return {
									label: item,
									value: item
								}
							}),
							sliderVal:[weightMin,weightMax],
							
						}
					}
					this.Model.defaultFilterOption3 = _.cloneDeep(this.Model.filterOption3);
				}else{
					this.tips(this,'warning',data.msg)
				}
			    
			});
			
		},
		//商品售价列表
		getProductList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {}
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/sale/saleOrder/customListBySearch',
				//url:'/api/sale/saleOrder/customListBySearch',
				data:{
					condition:params,
					pageIndex: pageIndex,
					pageSize: pageSize,
				}
			}).then((res)=>{
				var data = res.data;	
				that.Model.tableDataDialog = [];
				if(data.status == 200){
					var obj = {};
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					console.log(data)
					for (var i = 0; i < result.length; i++) {				
						that.Model.tableDataDialog.push(result[i]);
					}
				}else{
					this.tips(this,'warning',data.msg)
				}
			    
			});
		},
		//点击确认添加商品
		addShop() {
			var commodityObject = this.Model.dialogTableChecked;
			commodityObject.idCard = this.Model.params.idCard;
			
			if(commodityObject.length == 0){
				this.tips(this,'warning','请勾选数据');
			}else{
				this.getPrice(this,commodityObject);
			}
			
		},
		//获取商品的价格
		getPrice(that,commodityObject){
			var idData = this.Model.idData;
			that.Model.commodityObject= {};
			var mainTableData = this.Model.tableData;
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/sale/saleOrder/getCustomGoods',
				//url:'/api/sale/saleOrder/getCustomGoods',
				data:commodityObject
			}).then((res)=>{
				 var data = res.data;
				 if(data.status == 200){
					var result = data.result;
					result.count = 1;
					result.isExpedited = false;  //加急
					result.isNeedWordArt = this.Model.shouldLettering; //是否需要艺术字
					result.isAddLogo = this.Model.isLogo; //外圈是否加DR LOGO
					result.isHigh = this.Model.isHighClass; //是否允许高配
					result.isAddLogoWord = this.Model.isLogo ? '是' : '否'; //外圈是否加DR LOGO（文字）
					result.isHighWord = this.Model.isHighClass ? '是' : '否'; //是否允许高配（文字）
					result.lettering = this.Model.letteringContent; //刻字
					result.customGoodsVo = commodityObject;

					//判断table是否有数据
					if(mainTableData.length>0){
						mainTableData.forEach((val,idx,arr)=>{
							//判断是否有求婚钻戒
							if(val.customGoodsVo.salesType == 'M05001'){
								this.$set(mainTableData,idx,result);
								//mainTableData.splice(0,1,result);
							}
							else{
								that.Model.tableData.push(result);
							}
						})
					}else{
						that.Model.tableData.push(result);
					}
					that.Model.changeGoodsDialogFlag = false;	
					//				
				 }else{
					that.tips(that,'warning',data.msg);
				 }
					
			});
		},
		selectedHighlight(data) {

		},
		//点击行 选中单选框
		handleRowClick(row){
			this.Model.dialogTableChecked = row;
		},
		//点击加急
		handleClickApproval(row) {
			if (!row.isExpedited) {
				row.isExpedited = true;
			} else {
				// 编辑状态下保存，将tempLabel的值付给label，退出编辑状态
			  row.isExpedited = false;
			}
			
		},
		//点击删除
		handleClickDelete(row) {
			var mainTableData = this.Model.tableData;
			var idData = this.Model.idData;
			var idx = mainTableData.indexOf(row);
			this.$confirm('此操作将永久删除该, 是否继续?', '提示', {
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			}).then(() => {
				mainTableData.splice(idx, 1);
				idData.splice(idx, 1);
				this.$message({
					type: 'success',
					message: '删除成功!'
				});
			}).catch(() => {
			           
			});
		},
		onSelectChange(type){
			const data = this.Model.sliderSelect[type];
			this.Model.sliderSelect[type].sliderVal = [data.value,data.value];
		},
		//点击确认订单
		onConfirmNew() {
			let params = this.Model.params;
			if(params.idCard.length == 0){
				this.tips(this, 'error', '请填写身份证号');
				return;
			}
			if(params.mobile.length == 0){
				this.tips(this, 'error', '请填写客户手机号');
				return;
			}
			if(params.manName.length == 0){
				this.tips(this, 'error', '请填写男士姓名');
				return;
			}
			if(params.womanName.length == 0){
				this.tips(this, 'error', '请填写女士姓名');
				return;
			}
			if(this.Model.tableData.length == 0){
				this.tips(this, 'error', '请添加商品');
				return;
			}
			this.Model.payPos = true;
			var payMethod = this.Model.params.isPosPay;					//支付方式
		},
		//确定提交
		onConfirmSubmit(pathName) {
			var params = this.Model.params;
			var mainTableData = this.Model.tableData;
			params.goodsList = mainTableData;
			//应付总金额
			params.amountPayable = this.Model.totlePrice;
			//订单金额
			params.orderAmount = this.Model.totlePrice;
			//支付金额
			params.payAmount = this.Model.totlePrice;
			//判断自提还是快递
			if(this.Model.params.shippingMethod == '0') {
				//收货信息
				params.saleReceivingList = [this.Model.checkedAddress];
			}else{
				//自提信息
				params.takeGoodsTime = this.Model.userSelfLift.takeGoodsTime;
				params.saleReceivingList = [this.Model.userSelfLift];

			}
			console.log(params)
			this.getNewOrder(this,params,pathName)
		},
		//跳转到添加支付信息、赠品信息
		toAddPayGift(pathName){
			this.onConfirmSubmit(pathName);
		},
		//修改地址
		TochangeAddress() {
			var AddressId = this.Model.radioAddress;
			var AddressArr = this.Model.params.saleReceivingList;
			var AddressObj = this.getDataObj(AddressId,AddressArr);
			this.Model.checkedAddress = AddressObj;
			this.Model.selectedOptions3 = objDeepCopy(AddressObj.locationArea);	//区域地址 联级选择器
			console.log(AddressObj.locationArea)
			//this.Model.changeAddress = false;
		},
		//遍历 得到label及value
		getDataObj(val,data){
			var obj;
			data.forEach(function(value,index,array){
				Object.keys(value).forEach(function(key){
					// console.log(key,value[key]);
					if(key == 'id' && value[key] == val){
						obj = value;
						return;
					}
				});
			})
			return obj;
			
		},
		//取消订单
		cancelOrder() {
			this.$router.push({
			  path:'customizeOrder',
			});
		},
		handleCurrentChange(val) {
			let params = this.Model.Searchparams;
			this.getProductList(this,params,val);
		},
		handleSizeChange(val) {
			let params = this.Model.Searchparams;
			this.getProductList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showSureBarCode(val) {
			this.Model.searchFromData = val;
		},
		showNotSureBarCodeP2(val) {
			this.Model.searchFromData3 = val;
		},
		//新增商品里的查询
		toSearchNotSureBarCode(val) {
			let slider = this.Model.sliderSelect.weight.sliderVal;
			let params = objDeepCopy(this.Model.searchFromData3);
			params.salesType = this.Model.searchObj.origin;
			params.styleId = this.Model.searchObj.modelName;
			params.startInsert = (slider[0]/100).toFixed(2);
			params.endInsert = (slider[1]/100).toFixed(2);
			console.log(params);
			this.Model.Searchparams = params;
			this.getProductList(this,params)
			/*this.Model.tab1TableDetail1.flag = true;*/
		},
		//新增商品里获取下拉框的事件
		showChild(val,changeOb,option) {
			switch (changeOb.key) {
				case 'series':
					var prams = val.series;
					this.changeStyleName(this,prams,option);
				break;
				case 'modelName':
					var prams = val.modelName;
					//获取第二步数据
					this.getParameters(this,prams,option);
				break;	
			}
			this.Model.searchObj = objDeepCopy(val);
			this.Model.filterOption2.items = _.cloneDeep(option);
		},
		handleSelectionChange(val) {
		  this.Model.TableSelectData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			//this.Model.filterOption3 = _.cloneDeep(this.Model.defaultFilterOption3);
		},
		toExport(val) {
			console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
		//自提获取所有城市
		getSelfLiftCities(that) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/crm/geographyCity/queryCityList?language=1&countryCode=CN',
				data:{}
			}).then((res)=>{
				var data = res.data;		
				if(data.status == 200){
					var result = data.result;
					that.Model.allCities = objDeepCopy(result);
				}else{
					this.tips(this,'warning',data.msg)
				}
			});
		},
		//获取门店
		changeStore(that,param) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url:apiTest+'/supplier/supplierShop/getList',
				data:{
					city:param
				}
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){				
					that.Model.cityStore = [];
					that.Model.deliverStores = [];  //发货门店
					var result = data.result;
					if(result){
						that.Model.cityStore = objDeepCopy(result);
						that.Model.deliverStores = objDeepCopy(result);
					}
				}else{
					that.tips(that,'warning',data.msg)
				}
			    
			});
		},
		//获取渠道
		getoriginChannel(that,param) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url:apiTest+'/sale/saleGoodsAttribute/getGoodsAttributelist',
				data:{
					attributeCode:"M23"
				}
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){				
					that.Model.originChannel = [];  //来源渠道
					var result = data.result;
					if(result){
						that.Model.originChannel = objDeepCopy(result);
					}
				}else{
					that.tips(that,'warning',data.msg)
				}
			    
			});
		},
		//获取门店信息
		checkStore(value) {
			this.changeStore(this,value);
		},
		//联机选择器 选择结束触发
		changecascards(val) {
			var labelStr = '';
			var cascaderArr = this.getCascaderObj(val, this.Model.options);
			for (let i = 0; i < cascaderArr.length; i++) {
				labelStr += cascaderArr[i].label;
			}
			
			// this.Model.checkedAddress.location = labelStr;
			
			this.Model.checkedAddress.countryCode = 'CN';
			this.Model.checkedAddress.countryName = '中国';
			this.Model.checkedAddress.provinceCode = cascaderArr[0].code;
			this.Model.checkedAddress.provinceName = cascaderArr[0].label;
			this.Model.checkedAddress.cityCode = cascaderArr[1].code;
			this.Model.checkedAddress.cityName = cascaderArr[1].label;
			this.Model.checkedAddress.areaCode = cascaderArr[2].code;
			this.Model.checkedAddress.areaName = cascaderArr[2].label;
			console.log(this.Model.checkedAddress)
		},
		//遍历 得到label及value
		getCascaderObj(val,opt){
			return val.map(function (value, index, array) {
		        for (var item of opt) {
		            if (item.code == value) {
						opt = item.children;
						return item;
					}
		        }
		        return null;
		    });
		},
		//合计
		getSummaries(param) {
			var that = this;
			const { columns, data } = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 0) {
				  sums[index] = '总价';
				  return;
				}else if(index === 5 ||index === 6 || index === 7 || index === 10) {
					const values = data.map(item => Number(item[column.property]));
					sums[index] = values.reduce((prev, curr) => {
					const value = Number(curr);
					if (!isNaN(value)) {
						return prev + curr;
					} else {
						return prev;
					}
					}, 0);
					if(index === 5){
						that.Model.totlePrice = sums[index];
					}else{

					}

				}else{
					sums[index] = '/';
				}
			});
			
			return sums;
		}
	}
}
export default Controller;
